package bb.lanxing.lib.devices.bryton.bbcp;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

class BbcpFileInputStream extends BbcpDataInputStream implements BbcpInputStream {
    private byte[] mAppendData;
    private String mFilePath;

    public BbcpFileInputStream(String str, BbcpCommand bbcpCommand, byte[] bArr) {
        super(null, bbcpCommand);
        this.mFilePath = str;
        this.mAppendData = bArr;
    }

    @Override
    public byte[] readPackage() throws BbcpValidationException {
        if (this.mData == null) {
            prepareData();
        }
        return super.readPackage();
    }

    private void prepareData() {
        try {
            FileInputStream fileInputStream = new FileInputStream(this.mFilePath);
            int available = fileInputStream.available();
            byte[] bArr = this.mAppendData;
            this.mData = new byte[bArr != null ? bArr.length + available : available];
            fileInputStream.read(this.mData, 0, available);
            byte[] bArr2 = this.mAppendData;
            if (bArr2 == null) {
                return;
            }
            System.arraycopy(bArr2, 0, this.mData, available, this.mAppendData.length);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }
}
